package com.socialrss.adapters;

import java.util.ArrayList;

import com.socialrss.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.view.ContextMenu;

public class SocialNetworkAdapter extends BaseAdapter {

	private Integer[] imgid = {
	   R.drawable.facebook_icon,
	   R.drawable.twitter_icon,
	   R.drawable.google_plus_icon,
	   R.drawable.instagram_icon,
	   };
	  
	private LayoutInflater l_Inflater;
	ArrayList<String> socialNetworksArraylist;
	private Context context;

	public SocialNetworkAdapter(Context context, ArrayList<String> results) {
		 this.context = context;
		 socialNetworksArraylist = results;
		 l_Inflater = LayoutInflater.from(context);
	 }
			 
	@Override
	public int getCount() {
		return socialNetworksArraylist.size();
	}

	@Override
	public Object getItem(int position) {
		return socialNetworksArraylist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = l_Inflater.inflate(R.layout.network_item, null);
			holder = new ViewHolder();
			holder.txt_socialNetworkName = (TextView) convertView.findViewById(R.id.ni_networkName);
			holder.itemImage = (ImageView) convertView.findViewById(R.id.ni_imgListIcon);
			convertView.setTag(holder);
		} 
		else {
			holder = (ViewHolder) convertView.getTag();
		}
   
		holder.txt_socialNetworkName.setText(socialNetworksArraylist.get(position));
		holder.itemImage.setImageResource(imgid[position]);

		return convertView;
	}
	static class ViewHolder {
	  TextView txt_socialNetworkName;
	  ImageView itemImage;
	}
}